﻿using ManoMachine.Assembler.Exceptions;
using ManoMachine.Assembler.Mnemonics.Descriptors;

namespace ManoMachine.Assembler.Parsers
{
    public class AssemblyLine
    {
        public int Number { get; internal set; }
        public string Code { get; internal set; }

        public string Label { get; internal set; }
        public string Comment { get; internal set; }

        public string[] InstructionParts { get; internal set; }

        public AssemblerException Error { get; internal set; }
        public MnemonicDescriptor MnemonicDescriptor { get; internal set; }

        public override string ToString()
        {
            string instructionParts = string.Empty;
            if (InstructionParts != null && InstructionParts.Length >= 1)
            {
                for (int index = 0; index < InstructionParts.Length - 1; index++)
                {
                    string parameter = InstructionParts[index];
                    instructionParts += string.Format("{{{0}}},", parameter);
                }
                instructionParts += string.Format("{{{0}}}", InstructionParts[InstructionParts.Length - 1]);                
            }
            return string.Format(
                @"
Number      : [{0}]
Code        : [{1}]
Label       : [{2}]
Comment     : [{3}]
Instruction : [{4}]
", 
                this.Number,
                this.Code,
                this.Label,
                this.Comment,
                instructionParts
                );
        }
    }
}
